<?php

	drupal_set_title('');
	$url = $config->getVar('url');
	drupal_add_js('misc/collapse.js');
	drupal_add_js('bdbdec/view/scripts/editUserAdmin.js.');
	drupal_add_js('bdbdec/view/scripts/JQueryValidate.js.');
	

echo '	
<div id="tabs-wrapper" class="clear-block">
		<h2 class="with-tabs">Modifier un utilisateur</h2>
		<ul class="tabs primary">
			<li>
				<a href="'.$url.'/bdbdec.php?action=addUser">Ajouter un utilisateur</a>
			</li>
			<li class="active">';
			if ($user->getGrade()->getType() == GRADE_TYPE_POWER && $user->isAllowedTo(GRADE_ADD_MEMBER))
				echo '<a class="active" href="'.$url.'/bdbdec.php?action=editUserPerm">Modifier un utilisateur</a>';
			else if ($user->getGrade()->getType() == GRADE_TYPE_ADMIN)
				echo '<a class="active" href="'.$url.'/bdbdec.php?action=editUserAdmin">Modifier un utilisateur</a>';
			echo '   
			</li>
		</ul>
	</div>
<form action="./bdbdec.php?action=editUserAdmin&amp;id='.$userToChange->getId().'"  accept-charset="UTF-8" method="post" id="edit-user-form">
	<div>
		<input type="hidden" name="form" id="edit-form" value="data" />
		<fieldset class="collapsible">
			<legend>Donn&eacute;es principales</legend>
			<div class="form-item" id="edit-login-wrapper">
				<label for="edit-login">
					Login: <span class="form-required" title="Champ requis.">*</span>
				</label>
				<input type="text" maxlength="30" name="login" id="edit-login" size="45" value="'.$userToChange->getLogin().'" class="form-text required" />
				<div class="description">Identifiant &agrave; utiliser lorsque vous vous connectez au site</div>
			</div>
			<div class="form-item" id="edit-lastname-wrapper">
				<label for="edit-lastname">
					Nom: <span class="form-required" title="Champ requis.">*</span>
				</label>
				<input type="text" maxlength="20" name="lastname" id="edit-lastname" size="30" value="'.$userToChange->getLastname().'" class="form-text required" />
			</div>
			<div class="form-item" id="edit-firstname-wrapper">
				<label for="edit-firstname">
					Pr&eacute;nom: <span class="form-required" title="Champ requis.">*</span>
				</label>
				<input type="text" maxlength="20" name="firstname" id="edit-firstname" size="30" value="'.$userToChange->getFirstname().'" class="form-text required" />
			</div>
			<div class="form-item" id="edit-email-wrapper">
				<label for="edit-email">
					Email: <span class="form-required" title="Champ requis.">*</span>
				</label>
				<input type="text" maxlength="30" name="email" id="edit-email" size="45" value="'.$userToChange->getEmail().'" class="form-text required email" />
			</div>
			<div class="form-item" id="edit-semester-wrapper">
				<label for="edit-semester">Semestre: </label>
				<select name="semester" class="form-select" id="edit-semester" >';
						$semesters = array('1'=>'TC01','2'=>'TC02','3'=>'TC03','4'=>'TC04','5'=>'TC05','6'=>'TC06','11'=>'GX01','12'=>'GX02','13'=>'GX03','14'=>'GX04','15'=>'GX05','16'=>'GX06','17'=>'GX07','18'=>'GX08','19'=>'GX09','20'=>'Autres');
						$semester = $userToChange->getSemester();
						foreach ($semesters as $id => $name)
						{
							if (strcmp($semester, $id) != 0)
								echo '<option value="'.$id.'">'.$name.'</option>';
							else
								echo '<option value="'.$id.'" selected="selected">'.$name.'</option>';
						}
					echo '
				</select>
			</div>
			<div class="form-item" id="edit-grade-wrapper">
				<label for="edit-grade">Grade: </label>
				<select name="grade" class="form-select" id="edit-grade" >';
				
					$gradeId = $userToChange->getGradeId();
					foreach ($gradeList as $grade)
					{
						if ($gradeId != $grade['id'])
							echo '<option value="'.$grade['id'].'">'.$grade['name'].'</option>';
						else
							echo '<option value="'.$grade['id'].'" selected="selected">'.$grade['name'].'</option>';
					}
				echo '
				</select>
			</div>
			<div class="form-item" id="edit-roles-wrapper">
				<label for="edit-grade">Role: </label>';
				
					$roleUser = $userToChange->getDrupalUser()->roles;
					foreach ($roleList as $role)
					{
						echo '<input name="role[]" type="checkbox" value="'.$role['rid'].'" ';
						if (is_array($roleUser) && array_key_exists($role['rid'], $roleUser)) echo 'checked="checked"';
						echo ' class="form-checkbox" /> '.htmlentities($role['name']).'<br />';	
						
					}
				echo '
				<div class="description">R&ocirc;le au sein du site web (acc&egrave;s aux diff&eacute;rentes parties du site)</div>
			</div>
			<div class="form-item" id="edit-comment-wrapper">
				<label for="edit-comment">Commentaires: </label>
				<textarea cols="45" rows="3" name="comment" id="edit-comment"  class="form-textarea resizable">'.$userToChange->getComment().'</textarea>
			</div>
			<div class="form-item" id="edit-paid-wrapper">
				<label class="option">
					<input type="checkbox" name="paid" id="edit-paid" value="1"'; 
						if ($userToChange->getPaid()) echo 'checked="checked"'; 
						echo 'class="form-checkbox" /> 
					Paiement de la cotisation effectu&eacute;
				</label>
			</div>
			<div class="form-item" id="edit-deposit-wrapper">
				<label class="option">
					<input type="checkbox" name="deposit" id="edit-deposit" value="1" ';
					 if ($userToChange->getDeposit()) echo 'checked="checked"';
					 echo ' class="form-checkbox" /> 
					Paiement de la caution effectu&eacute;
				</label>
			</div>
			<div class="form-item" id="edit-saveRecords-wrapper">
				<label class="option">
					<input type="checkbox" name="saveRecords" id="edit-saveRecords" value="1" ';
					if ($userToChange->getSaveRecords()) echo 'checked="checked"'; 
					echo ' class="form-checkbox" /> 
					Autoriser la BDBDEC &agrave; publier mes donn&eacute;es
				</label>
			</div>
			<input type="submit" name="op" id="edit-submit" value="Enregistrer"  class="form-submit" />
		</fieldset>
	</div>
</form>
<form action="./bdbdec.php?action=editUserAdmin&amp;id='.$userToChange->getId().'"  accept-charset="UTF-8" method="post" id="change-user-password-form">
	<div>
		<input type="hidden" name="form" id="edit-form-1" value="pass"  />
		<fieldset class="collapsible">
			<legend>Changer de mot de passe</legend>
			<div class="form-item" id="edit-password-wrapper">
				<label for="edit-password">
					Mot de passe: <span class="form-required" title="Champ requis.">*</span>
				</label>
				<input type="password" name="password" id="edit-password"  maxlength="32"  size="45"  class="form-text required" />
			</div>
			<div class="form-item" id="edit-passwordconf-wrapper">
				<label for="edit-passwordconf">
					Confirmation du mot de passe: <span class="form-required" title="Champ requis.">*</span>
				</label>
				<input type="password" name="passwordconf" id="edit-passwordconf"  maxlength="32"  size="45"  class="form-text required" />
			</div>
			<input type="submit" name="op" id="edit-password-submit" value="Enregistrer"  class="form-submit" />
		</fieldset>
	</div>
</form>
<form action="./bdbdec.php?action=deleteUser&amp;id='.$userToChange->getId().'"  accept-charset="UTF-8" method="post" id="change-user-password-form">
	<div>
		<input type="hidden" name="form" id="edit-form-1" value="pass"  />
		<fieldset class="collapsible">
			<legend>Supprimer l\'utilisateur</legend>
			<input type="submit" name="op" id="delete-submit" value="Supprimer"  class="form-submit" />
		</fieldset>
	</div>
</form>';
?>